﻿package com.hnev.gui;

import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

public class Login extends JFrame{
	
	JPanel panel;//中间容器
	JLabel lblName,lblPwd;
	JTextField txtName;
	JPasswordField txtPwd;
	JButton btLogin,btReturn;
	
	public Login(){
//		setSize(600,600);//尺寸
//		setLocation(400, 80);//位置
//		setVisible(true);//可见性
//		setTitle("水果超市登陆界面");
//		setDefaultCloseOperation(Welcome.EXIT_ON_CLOSE);
		panel = new JPanel(new GridLayout(3,1));
		panel.setBorder(new EmptyBorder(200,5,100,5));//上左下右
		lblName=new JLabel("用  户  名：");
		lblPwd=new JLabel("密         码：");
		txtName=new JTextField(16);
		txtPwd=new JPasswordField(16);
		btLogin = new JButton("登录");
		btReturn = new JButton("返回");
		
		
		
		JPanel p1= new JPanel(new FlowLayout(FlowLayout.CENTER));
		p1.add(lblName);
		p1.add(txtName);
		panel.add(p1);
		
		JPanel p2= new JPanel(new FlowLayout(FlowLayout.CENTER));
		p2.add(lblPwd);
		p2.add(txtPwd);
		panel.add(p2);
		
		JPanel p3= new JPanel(new FlowLayout(FlowLayout.CENTER,100,0));
		p3.add(btLogin);
		p3.add(btReturn);
		
		panel.add(p3);
		
		this.add(panel);
		this.setSize(600, 600);
		this.setLocationRelativeTo(null);
		this.setResizable(false);
		this.setVisible(true);
		
		class MyActionListener implements ActionListener{

			@Override
			public void actionPerformed(ActionEvent e) {
				String userName =txtName.getText().trim();
				String password = new String(txtPwd.getPassword());
				
				Object source=e.getSource();
				if(source.equals(btLogin)){
					if(userName.equals("admin")&&password.equals("123456")){
						new JDBC();
						
					}else {

						JOptionPane.showMessageDialog(null, "登陆失败", "登陆失败提示框",JOptionPane.WARNING_MESSAGE); 
						
					}
					
				
					
					
				
				}else if(source.equals(btReturn)){
					new Welcome();
				}
			
			}
		}

		MyActionListener listener = new MyActionListener();
		btLogin.addActionListener(listener);
		btLogin.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				
				
			}
			
		});
	  }

	
	public static void main(String[] args) {
		new Login();
	}
}
